﻿using NForum.Core.Abstractions;
using System;
using System.ComponentModel.DataAnnotations;
using System.Xml.Linq;

namespace NForum.Core {

	public class Post : ICustomPropertyHolder, IAuthoredElement {
		public Int32 Id { get; set; }
		[Required]
		public Int32 TopicId { get; set; }
		[Required]
		public Int32 AuthorId { get; set; }
		[Required]
		public Int32 EditorId { get; set; }

		public Int32? ParentPostId { get; set; }

		private DateTime created;
		[Required]
		public DateTime Created {
			get {
				return created;
			}
			set {
				this.created = value.FixTimeZone();
			}
		}
		private DateTime changed;
		[Required]
		public DateTime Changed {
			get {
				return this.changed;
			}
			set {
				this.changed = value.FixTimeZone();
			}
		}

		[Required]
		public PostState State { get; set; }

		[Required]
		[StringLength(Int32.MaxValue)]
		public String Subject { get; set; }
		[Required]
		[StringLength(Int32.MaxValue)]
		public String Message { get; set; }

		[StringLength(Int32.MaxValue)]
		public String CustomProperties { get; set; }
		public XDocument CustomData { get; set; }

		public virtual Topic Topic { get; set; }
		public virtual User Author { get; set; }
		public virtual User Editor { get; set; }
		public virtual Post ParentPost { get; set; }
	}
}